/**
 * file :	config.h
 * author :	bushaofeng
 * created :	2013-02-07 16:58
 * func : 
 */

#ifndef	__CONFIG_H_
#define	__CONFIG_H_

#include "bs_conf.h"
class Config{
    public:
        Config(){}
        Config(const char* path){
            read(path);
        }
        ~Config(){
            bs_conf_destroy(&m_conf);
        }
        
        bool read(const char* path){
            int res;
            if((res=bs_conf_read(&m_conf, path))!=BS_SUCCESS){
                fprintf(stderr, "Read conf[%s] error[%d]\n", path, res);
                fflush(stderr);
            }

            return res>=0;
        }

        const char* getString(const char* name){
            return bs_conf_getstr(&m_conf, name);
        }

        int getInt(const char* name){
            return bs_conf_getint(&m_conf, name);
        }

        bool getBool(const char* name){
            const char* value = bs_conf_getstr(&m_conf, name);
            const char* truevalue[] = {"1", "YES", "yes", "Yes", "true", "TRUE", "True"};
            for(int i=0; i<sizeof(truevalue)/sizeof(char*); i++){
                if(strcmp(value, truevalue[i])==0){
                    return true;
                }
            }

            return false;
        }

        size_t getSize(){return bs_conf_size(&m_conf);}
        const char* getName(int i){
            return bs_conf_getname(&m_conf, i);
        }
        
    private:
        bs_conf_t   m_conf;
};

#endif
